package com.lnsf.bookstore.system.role.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lnsf.bookstore.system.role.dao.RolePermissionMapper;
import com.lnsf.bookstore.system.role.vo.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lnsf.bookstore.system.role.dao.RoleMapper;
import com.lnsf.bookstore.system.role.service.RoleService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class RoleServiceImpl implements RoleService {

	@Autowired
	private RoleMapper roleMapper;

	@Autowired
	private RolePermissionMapper rolePermissionMapper;


	@Override
	public List<Role> selectLevel() {
		return roleMapper.selectLevel();
	}

	@Override
	public PageInfo<Role> selectAll(Map<String, Object> map, Role role) {
		/*if(map.size()!=0) {
			PageHelper.startPage(Integer.parseInt(map.get("page").toString()), Integer.parseInt(map.get("limit").toString()));
		}*/
		return new PageInfo<Role>(roleMapper.selectAll(map));
	}

	@Override
	@Transactional
	public void deleteBatch(Integer[] roleIds) {
		roleMapper.deleteBatch(roleIds);
	}

	@Override
	@Transactional
	public int save(Role role) {
	   return 	roleMapper.insertSelective(role);
	}

	@Override
	@Transactional
	public int update(Role role) {
		return roleMapper.updateByPrimaryKeySelective(role);
	}

	@Override
	@Transactional
	public int delete(Integer roleId) {
		return roleMapper.deleteByPrimaryKey(roleId);
	}

	@Override
	public Role selectById(Integer roleId) {
		return roleMapper.selectByPrimaryKey(roleId);
	}

	@Override
	public long countByUserIdAndName(Integer userId, String name) {
		return roleMapper.countByUserIdAndName(userId,name);
	}
}
